var Paddle = function(game) {
    var image = game.imageByName('paddle')
    var o = {
        name: "paddle", 
        image: image,
        w: image.width,
        h: image.height,
        x: 100,
        y: 200,
        speed: 5,
    }

    o.move = function(x) {
        if (x < 0) {
            x = 0
        }
        if (x > (400 - o.image.width)) {
            x = 400 - o.image.width
        }
        o.x = x
    }
    o.moveLeft = function() {
        o.move(o.x - o.speed)
    }

    o.moveRight = function() {
        o.move(o.x + o.speed)
    }
    o.collide = function(guaImage) {
        // 碰撞算法，简单点，判断一个矩形的四个点是否在另一个矩形中
        var left = guaImage.x
        var right = guaImage.x + guaImage.image.width
        var up = guaImage.y
        var down = guaImage.y + guaImage.image.height

        if ((left >= o.x && left < o.x + o.image.width) && (up >= o.y && up < o.y + o.image.height)) {
            return true
        }
        if ((right >= o.x && right < o.x + o.image.width) && (up >= o.y && up < o.y + o.image.height)) {
            return true
        }
        if ((left >= o.x && left < o.x + o.image.width) && (down >= o.y && down < o.y + o.image.height)) {
            return true
        }
        if ((right >= o.x && right < o.x + o.image.width) && (down >= o.y && down < o.y + o.image.height)) {
            return true
        }
        return false
    }
    return o
}